<template>
	<!-- <view class="box screen-all flex">
		<head-navigation></head-navigation>
		<scroll-view class="screen-all" scroll-y>
			<view class="top-view flex center">
				<image class="top-icon" src="../../static/cunjiu_top.png"></image>
			</view>
			<view class="content-view flex">
				<view class="item-view flex row aCenter">
					<text class="input-title">{{role == 2 || role == 3 || role == 4 || role == 5 ? '客户姓名' : '姓名'}}</text>
					<input class="input-text flex-1" v-model="name" placeholder="请输入姓名" />
				</view>
				<view class="item-view flex row aCenter">
					<text class="input-title">{{role == 2 || role == 3 || role == 4 || role == 5 ? '客户电话' : '联系方式'}}</text>
					<input class="input-text flex-1" v-model="phone" type="number" placeholder="请输入手机号码" />
				</view>
				<view class="item-view-mark flex">
					<text class="input-title-mark">输入存酒详情</text>
					<textarea class="textarea-view" v-model="mark" placeholder="请输入存酒详情,包括种类/数量"></textarea>
				</view>
			</view>
			<view class="day-view flex">
				<view class="item-view flex row aCenter">
					<text class="input-title-mark">选择过期时间：</text>
				</view>
				<view class="time-view flex row aCenter">
					<view :class="[ timeType == 1 ? 'time-item-view-active':'time-item-view', 'flex center']" @click="timeType=1">
						7天
					</view>
					<view :class="[ timeType == 2 ? 'time-item-view-active':'time-item-view', 'flex center']" @click="timeType=2">
						30天
					</view>
				</view>
			</view>
			<view class="btm-env"></view>
		</scroll-view>
		
		<view class="bom-btn flex center" @click="onSubmit">
			确认存入
		</view>
	</view> -->
	<view class="">
		<view class="content"  v-if="tts==1">
			<view class="head"></view>
			<view class="body">
				<view class="shuru">
					<view class="label">
						客户电话：
					</view>
					<input type="number" v-model="phone" placeholder="请输入客户电话" placeholder-class="pclass" />
				</view>
		
				<view class="list">
					<view class="title">
						请选择存酒内容
					</view>
					<view class="uni-form-item uni-column">
						<picker @change="bindPickerChange" :value="indexss" :range="array" range-key="table_number">
							<label class="" v-if="dd==2">{{array[indexss]['table_number']}}</label>
							<label class="" v-if="dd==1">请选择桌位</label>
						</picker>
					</view>
					<view class="list-item" v-for="(item,index) in list" :key="index">
						<view class="item1">
							<view class="left" @click="selectWine(index)">
								{{item.name}}
							</view>
		
							<view class="right">
								<radio-group name="" v-if="item.type==2" :data-index="index" @change="changeRadio">
									<label>
										<radio style="transform: scale(0.7);" value="a" color="#934BD7"
											:checked="item.is_kf==1" /><text>开封</text>
									</label>
									<label>
										<radio style="transform: scale(0.7);" value="b" color="#934BD7"
											:checked="item.is_kf==0" /><text>未开封</text>
									</label>
								</radio-group>
							</view>
						</view>
		
						<view class="item2">
							<view class="left">
								<view class="items1">
									存入数量：
								</view>
								<view class="items2">
									<input type="number" v-model="item.num" />
									<view class="guige" v-if="item.type==1">
										瓶
									</view>
									<view class="guige" v-if="item.type==2&&item.is_kf==0">
										瓶
									</view>
									<view class="guige" v-if="item.type==2&&item.is_kf==1">
										cm
									</view>
								</view>
							</view>
							<view class="right" @click="delItem(index)">
								删除
							</view>
						</view>
					</view>
		
					<view class="add-btn" @click="addItem()">
						<image src="../../static/add_btn.png" mode=""></image>
					</view>
				</view>
			</view>
			<view style="height: 200rpx;">
		
			</view>
			<dwonSelect ref="dwonSelect" @getData="getDataDetail"></dwonSelect>
			<view class="foot">
				<view class="btns" @click="onSubmit">
					确认存入
				</view>
			</view>
		</view>
		<view class="tjj_er" v-if="tts==0">
			<image src="../../static/kong.png" mode="widthFix" class="tjj_yi"></image>
			<view>您的账号非服务员，没有权限访问</view>
		</view>
	</view>

</template>

<script>
	import dwonSelect from '../../components/dwonSelect/dwonSelect.vue'
	export default {
		components: {
			dwonSelect
		},
		data() {
			return {
				name: '',
				phone: '',
				mark: '',
					tts:1,

				timeType: 0, // 1=7天  2=30天
				role: 0,

				list: [{
					id: 0,
					name: "请选择酒名", //酒名字
					tyep: 3, //酒类型	
					num: "", //数量
					is_kf: 0, //1已开封0未开封
				}],
				current: 0,
				array: [],
				indexss: 0,
				dd: 1,
				table_id: ''
			}
		},
		onLoad() {
			this.role = uni.getStorageSync('role');

			// role -->  2达人  3达人助理  4管理员  5服务员
			if(this.role == 5){
				//如果是服务员才可以进行存酒操作。
			}else{
				//其他身份不可操作存酒
				this.tts=0
			}
		},
		onShow() {
			this.$request("api/index/table")
				.then(({
					code,
					msg,
					data,
					time
				}) => {
					console.log(code, msg, data);
					if (code == 1) {
						console.log(data)

						this.array = data
					} else {

					}
				}).catch((e) => {
					console.log(e);
				});
		},
		methods: {
			//下拉框
			bindPickerChange: function(e) { //改变的事件名
				this.indexss = e.detail.value;
				console.log(this.indexss)
				// this.$forceUpdate()
				for (var i = 0; i < this.array.length; i++) {
					this.table_id = this.array[this.indexss].id
				}
				console.log(this.table_id)
				this.dd = 2
			},

			changeRadio(e) {
				console.log(e)
				var index = e.currentTarget.dataset.index
				if (e.detail.value == 'a') {
					this.list[index].is_kf = 1
				} else {
					this.list[index].is_kf = 0
				}

			},
			getDataDetail(e) {
				this.list[this.current].id = e.id;
				this.list[this.current].name = e.name
				this.list[this.current].type = e.type
			},
			/**
			 * 选择酒
			 * @param {Object} index
			 */
			selectWine(index) {
				this.current = index
				this.$refs.dwonSelect.changeShow(true, this.list[index].id);
			},
			/**
			 * 新增元素
			 */
			addItem() {

				let last_item = this.list[this.list.length - 1];
				if (last_item.id == 0) {
					uni.showToast({
						title: '请选择酒名',
						icon: 'none'
					})
					return;
				}
				if (last_item.num == "") {
					uni.showToast({
						title: '请输入数量',
						icon: 'none'
					})
					return;
				}
				let item = {
					id: 0,
					name: "请选择酒名", //酒名字
					tyep: 3, //酒类型
					num: "", //数量
					is_kf: 0, //1已开封0未开封
				}

				this.list.push(item)
				setTimeout(() => {
					uni.pageScrollTo({
						scrollTop: 999999999999,
						duration: 200
					});
				}, 50);
			},
			delItem(index) {
				uni.showModal({
					title: '提示',
					content: '确定要删除吗？',
					confirmColor: '#010B24',
					success: (r) => {
						if (r.confirm) {
							if (this.list.length == 1) {
								uni.showToast({
									title: '最后一个元素禁止删除！',
									icon: 'none'
								})
								return;
							}
							this.list.splice(index, 1)
						}
					}
				})

			},
			onSubmit() {
				if (!this.phone) {
					uni.showToast({
						title: '请输入手机号码',
						icon: 'none'
					});
					return;
				}
				let last_item = this.list[this.list.length - 1];
				if (last_item.id == 0) {
					uni.showToast({
						title: '请选择酒名',
						icon: 'none'
					})
					return;
				}
				if (last_item.num == "") {
					uni.showToast({
						title: '请输入数量',
						icon: 'none'
					})
					return;
				}
				if (this.table_id == "") {
					uni.showToast({
						title: '请选择桌位号',
						icon: 'none'
					})
					return;
				}


				let params = {
					token: uni.getStorageSync("token"),
					phone: this.phone,
					data: JSON.stringify(this.list),
					table_id: this.table_id
				}
				console.log(params);
				this.$request("api/Index/add_alcohol", params)
					.then(({
						code,
						msg,
						data,
						time
					}) => {
						console.log(code, msg, data);
						uni.showToast({
							title: msg,
							icon: 'none'
						});
						if (code == 1) {
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						} else {

						}
					}).catch((e) => {
						console.log(e);
					});
			},
		}
	}
</script>

<style scoped lang="scss">
	.tjj_er{
		width: 100%;
		height: 100vh;
		background-color: #fff;
		text-align: center;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #959595;
	}
	.tjj_yi{
		width: 300rpx;
		margin-top: 240rpx;
		max-height: 300rpx;
	}
	.content {
		.foot {
			position: fixed;
			bottom: 0;
			width: 100%;

			.btns {
				height: 124rpx;
				background: #010B24;
				width: 100%;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				text-align: center;
				color: #FFFFFF;
				line-height: 124rpx;
			}
		}

		.head {
			height: 286rpx;
			background: #010B24;
			border-radius: 0rpx 0rpx 25rpx 25rpx;
		}

		.body {
			margin-top: -200rpx;

			.list {
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 21rpx 0rpx rgba(202, 202, 202, 0.42);
				border-radius: 20rpx;
				margin: 0 32rpx;
				margin-top: 19rpx;
				padding-bottom: 42rpx;

				.title {
					padding-top: 35rpx;
					padding-left: 33rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #272727;
				}

				.add-btn {
					border: 1rpx solid #D3D3D3;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 64rpx;
						height: 64rpx;
					}

					border-radius: 50rpx;
					margin: 0 32rpx;
					margin-top: 34rpx;
				}

				.list-item {
					background: #F7F7F7;
					border: 2rpx solid #E5E5E5;
					border-radius: 20rpx;
					margin: 0 32rpx;
					margin-top: 30rpx;
					padding-bottom: 29rpx;

					.item2 {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 25rpx;

						.left {
							align-items: center;
							display: flex;
							margin-left: 32rpx;

							.items1 {
								font-size: 26rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #272727;
							}

							.items2 {
								width: 160rpx;
								height: 63rpx;
								background: #FFFFFF;
								border: 1rpx solid #E5E5E5;
								border-radius: 10rpx;
								display: flex;
								align-items: center;
								padding: 0 10rpx;

								input {
									text-align: center;
									font-size: 26rpx;
									color: #272727;
								}

								.guige {
									font-size: 26rpx;
									font-family: PingFang SC;
									font-weight: 500;
									color: #272727;
									opacity: 0.46;
								}
							}
						}

						.right {
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #E03939;
							margin-right: 37rpx;
						}
					}

					.item1 {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding-top: 26rpx;

						.left {
							width: 291rpx;
							height: 63rpx;
							background: #FFFFFF;
							border: 1rpx solid #E5E5E5;
							border-radius: 10rpx;
							text-align: center;
							line-height: 63rpx;
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #272727;
							margin-left: 31rpx;
							white-space: nowrap;
							/*超出的空白区域不换行*/
							overflow: hidden;
							/*超出隐藏*/
							text-overflow: ellipsis;
							/*文本超出显示省略号*/
						}

						.right {
							margin-right: 36rpx;
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #272727;
						}
					}
				}
			}

			.shuru {
				height: 92rpx;
				background: #FFFFFF;
				border-radius: 46rpx;
				margin: 0 32rpx;
				display: flex;
				align-items: center;
				padding-left: 42rpx;

				.label {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #272727;
				}

				input {
					margin-left: 30rpx;
					font-size: 28rpx;
					color: #272727;
				}

				.pclass {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #A1A1A1;
				}
			}
		}
	}



	.box {}

	.top-view {
		width: 100%;
		height: 375rpx;
		background-color: #010B24;
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
	}

	.top-icon {
		width: 550rpx;
		height: 195rpx;
		margin-bottom: 100rpx;
	}

	.content-view {
		width: 690rpx;
		border-radius: 20rpx;
		background-color: #FFF;
		margin-left: 30rpx;
		padding: 0 30rpx;
		margin-top: -130rpx;
	}

	.day-view {
		width: 690rpx;
		border-radius: 20rpx;
		background-color: #FFF;
		margin-left: 30rpx;
		padding: 0 30rpx;
		margin-top: 20rpx;
	}

	.item-view {
		width: 100%;
		height: 130rpx;
		border-bottom: 1rpx solid #EFEFEF;
	}

	.input-title {
		width: 230rpx;
		font-size: 28rpx;
		color: #121212;
	}

	.input-text {
		font-size: 28rpx;
		color: #121212;
	}

	.item-view-mark {
		width: 100%;
		padding-top: 40rpx;
		margin-bottom: 60rpx;
	}

	.input-title-mark {
		font-size: 28rpx;
		color: #121212;
	}

	.textarea-view {
		box-sizing: border-box;
		width: 100%;
		margin-top: 20rpx;
		padding: 20rpx 36rpx;
		background-color: #F6F6F6;
		font-size: 28rpx;
		color: #121212;
	}

	.time-view {
		justify-content: space-between;
		margin: 36rpx 0;
	}

	.time-item-view {
		width: 294rpx;
		height: 96rpx;
		background-color: #EEE;
		border-radius: 18rpx;
		font-size: 28rpx;
		color: #121212;
	}

	.time-item-view-active {
		width: 294rpx;
		height: 96rpx;
		background-color: #934BD7;
		border-radius: 18rpx;
		font-size: 28rpx;
		color: #FFF;
	}

	.bom-btn {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 120rpx;
		background-color: #010B24;
		font-size: 28rpx;
		color: #FFF;
	}

	.bom-btn:active {
		background-color: #010B24EF;
	}

	.btm-env {
		width: 100%;
		height: 200rpx;
	}

	.uni-column {
		width: 624rpx;
		height: 62rpx;
		background: #FFFFFF;
		border: 1rpx solid #E5E5E5;
		border-radius: 10rpx;
		text-align: center;
		line-height: 62rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #272727;
		margin-left: 30rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-top: 20rpx;
	}
</style>
